package cl.sms.service;

import cl.sms.service.R.drawable;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

/**
 * 
 * @author MariaJose
 *
 */
public class AndroidSmsService extends Activity {



	private ImageView imagen ;
	private SharedPreferences prefs ;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.servicio);

		Button buttonStart = (Button)findViewById(R.id.startalarm);
		Button buttonCancel = (Button)findViewById(R.id.cancelalarm);
		imagen = (ImageView) findViewById(R.id.iconosmsstar_stop);

		/**Boton start*/
		buttonStart.setOnClickListener(new Button.OnClickListener(){

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				imagen.setImageResource(R.drawable.star1_1);
				startServiceSMS();
				Toast.makeText(AndroidSmsService.this, "Start Service", Toast.LENGTH_LONG).show();
			}});

		/**Boton cancelar*/
		buttonCancel.setOnClickListener(new Button.OnClickListener(){

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				imagen.setImageResource(R.drawable.stop1_1);
				stopServiceSMS();
				Toast.makeText(AndroidSmsService.this, "Cancel!", Toast.LENGTH_LONG).show();

			}});

	}

	/**
	 * COmienza el servicio
	 */
	public void startServiceSMS(){

		Intent i = new Intent(this, SmsService.class);  
		startService(i);  
	}

	/**
	 * Finaliza el Servicio
	 */
	public void stopServiceSMS(){

		Intent i = new Intent(AndroidSmsService.this, SmsService.class);
		stopService(i);
		finish();
	}

	/**
	 * Menu opcional de la lista de sms
	 */
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.menusms, menu);
		return true;
	}

	/**
	 * opciones al apretar  los botones en la lista sms
	 */
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle item selection
		switch (item.getItemId()) {

		case R.id.opcconfigura:

			Toast.makeText(getApplicationContext(), "Configuracion", 10).show();
			Intent i = new Intent();
			i.setClass(getApplicationContext(), Configuracionsms.class);
			startActivity(i);

			return true; 
		case R.id.opcsalir:
			Toast.makeText(getApplicationContext(), "Hasta luego!", 10).show();
			this.finish();
			super.onDestroy();
			
			return true; 
		default: 

			return super.onContextItemSelected(item);
		}
	}

}


